<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="text/babel">
      run(async function () {
        const {
          React,
          ReactDOM: { render },
          WebChat: {
            FluentThemeProvider,
            Components: { BasicWebChat, Composer },
            hooks: { useSendBoxValue }
          }
        } = window; // Imports in UMD fashion.

        const { directLine, store } = testHelpers.createDirectLineEmulator();

        const RunFunction = ({ fn }) => {
          fn();

          return false;
        };

        const renderWithFunction = fn =>
          new Promise(resolve =>
            ReactDOM.render(
              <FluentThemeProvider>
                <Composer directLine={directLine} store={store}>
                  <BasicWebChat />
                  <RunFunction fn={() => resolve(fn && fn())} key={Date.now() + ''} />
                </Composer>
              </FluentThemeProvider>,
              document.getElementById('webchat')
            )
          );

        await renderWithFunction();

        await pageConditions.uiConnected();

        await host.click(document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`));
        await host.sendKeys('Hello, World!');

        await expect(renderWithFunction(() => useSendBoxValue()[0])).resolves.toBe('Hello, World!');
        await renderWithFunction(() => useSendBoxValue()[1]('Aloha!'));

        expect(document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`).value).toBe('Aloha!');
      });
    </script>
  </body>
</html>
